#pragma once

#include "vrdatacore_global.h"
#include "meshdrawableactor.h"
#include "StatusActor.h"
#include <QVector>
#include "transformable.h"
#include "physical.h"

namespace VrDataCore
{
	class Map;

	class VRDATACORE_EXPORT EnvironmentMesh:public CoreBase::Physical
	{
	public:
		EnvironmentMesh(CoreBase::ActorBase* owneractor,const QString& name = "EnvironmentMesh");
		EnvironmentMesh(osg::MatrixTransform& node,CoreBase::ActorBase* owneractor, const QString& name = "EnvironmentMesh");

		virtual void addedToScene(CoreBase::Scene* scene);
		void setMeshFile(const QString& file);
		QString getMeshFile();
		void addObjects(QVector<osg::Vec3> posvector);
		QVector<osg::Vec3> getObjects(const osg::Vec3& center,float radious);
		QVector<osg::Vec3> getObjects(const osg::Vec3& min,const osg::Vec3& max);
		QVector<osg::Vec3> getAllObjects();
		void removeObjects(QVector<osg::Vec3> posvector);
		struct EnvironmentObject
		{
			osg::Vec3													_pos;
			osg::ref_ptr<CoreBase::Transformable>						_node;
		};
		void setCollisionType(int type);
		int getCollisionType();
	protected:
		~EnvironmentMesh();
		void loadMesh();
		QString															_meshFile;
		bool															_haveInScene;
		osg::ref_ptr<osg::Node>											_node;
		QMap<float,EnvironmentObject>									_posToNode;
		int																_collisionType;
		float															_treeHeight;
	};

	class VRDATACORE_EXPORT EnvironmentObjectActor:public MeshDrawableActor
	{
	public:
		EnvironmentObjectActor(void);
		virtual void buildPropertyMap();
		virtual osg::ref_ptr<CoreBase::ActorBase> clone();
		virtual void onMapLoadBegin(CoreBase::Map*){}
		virtual void onMapLoadEnd(CoreBase::Map*);
		void addObjects(QVector<osg::Vec3> posvector);
		QVector<osg::Vec3> getObjects(const osg::Vec3& center,float radious);
		QVector<osg::Vec3> getObjects(const osg::Vec3& min,const osg::Vec3& max);
		QVector<osg::Vec3> getAllObjects();
		void removeObjects(QVector<osg::Vec3> posvector);
		void setMeshFile(QString file);
		QString getMeshFile();
		void setCollisionType(int type);
		int getCollisionType();
		void setObjectsList(QString list);
		QString getObjectsList();
	protected:
		virtual ~EnvironmentObjectActor(void);
		virtual void addToMapEnd(CoreBase::Map*);
		virtual void removeFromMapEnd(CoreBase::Map*);
		virtual void createDrawable();
		QString									_objectList;
	};
}